<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/conn.asp"-->
<!--#include file="lib/saferequest.asp"-->
<!--#include file="lib/error_write.asp"-->
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<link rel="stylesheet" href="lib/sheet.css" type="text/css" />
<link type="text/css" rel="stylesheet" href="lib/jquery_ui_lastest/themes/base/jquery_ui_lastest.css" />
<!-- jquery和ui -->
<script type="text/javascript" src="lib/jquery_lastest.js"></script>
<script type="text/javascript" src="lib/jquery_ui_lastest/jquery_ui_lastest.js"></script>
<script type="text/javascript" src="lib/jquery_ui_lastest/i18n/jquery_ui_datepicker_zh_CN_lastest.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&language=zh-CN"></script>
<script type="text/javascript">
	$(function() {
		$(".bt").ajaxStart(function(){
			$(this).attr("disabled","disabled");
		});
		$(".bt").ajaxStop(function(){
			$(this).removeAttr("disabled");
		});
		$.datepicker.setDefaults({
			changeMonth: true,
			changeYear: true
		});
		$(".datepicker").datepicker();
		$(".contable").addClass("ct");	//载入table样式
		$(".contable th").addClass("ch").css("background-color","silver");	//载入th样式
		$(".contable td").addClass("ld");	//载入td样式
		function didian_xiangxing(dd_val,xx_val){
			$.get("yj.asp",{didian:dd_val,xiangxing:xx_val},function(data){
				//alert(data);
				if (!data){
					$("#yj,#jsj,#chanzhi").val(0);
					return false;
				}
				$("#yj").val(data.yunjia);
				$("#zdyj").html(data.yunjia);

				//$("#rlf,#sjrlf").val(data.zdrlf);
				if(data.jsj==""){$("#jsj").val("0")} else {$("#jsj").val(data.jsj)};
				$("#dz").val((parseFloat($("#yfjgf").val())+parseFloat($("#jsj").val()))*0.6);
				$("#chanzhi").val(data.chanzhi);
			},"json");
		
		}
		$("#didian,#xx").change(function(){
			didian_xiangxing($("#didian").val(),$("#xx").val());
		});
		$("#dd").change(function(){
			$("#didian").val($("#dd").val());
			didian_xiangxing($("#dd").val(),$("#xx").val());
		});
		$("#tixiang,#huanxiang").change(function(){
			var tx=txf=hx=hxf=0;
			$.get("tx.asp",{tx:$("#tixiang").val()},function(data){
				//alert(data);
				if(!data){ tx=0;txf=0;}else{ tx=data.tx;txf=data.txf;}
				$("#jgf").val(tx+hx);
				$("#yfjgf").val(txf+hxf);
				$("#dz").val((txf+hxf+parseFloat($("#jsj").val()))*0.6);
			},"json");
			$.get("hx.asp",{hx:$("#huanxiang").val()},function(data){
				//alert(data);
				if(!data){ hx=0;hxf=0;}else{ hx=data.hx;hxf=data.hxf;}
				$("#jgf").val(tx+hx);
				$("#yfjgf").val(txf+hxf);
				$("#dz").val((txf+hxf+parseFloat($("#jsj").val()))*0.6);
			},"json");
		});
		var j=-1;
		function getkeycode(e){
			var keyc;
			if(window.event){
				keyc=e.keyCode;
			}else if(e.which){
				keyc=e.which;
			}
			return keyc;
		}

		function tyrover(n,mn){
			for(var i=0;i<mn;i++){
				if(i>=0&&i<mn&&i==n){
					$("#ttyr tr").eq(i).addClass("gac_b");	//添加css样式
				}else{
					$("#ttyr tr").eq(i).removeClass("gac_b");	//添加css样式
				}

			}

		}

		$("#tyr").keyup(function(e){
			var tyr=$("#tyr");
			if(getkeycode(e)==13||getkeycode(e)==38||getkeycode(e)==40){
				var	ttr=$("#ttyr tr");
				if(getkeycode(e)==13&&($("#ttyr").css("visibility")=="visible")) {
					//alert(j);
					tyr.val(ttr.eq(j).text());
					j=-1;
					$("#ttyr").css("visibility","hidden");
				}
				if(getkeycode(e)==40){
					j++;
					if(j>=ttr.length) j=0;
					tyr.val(ttr.eq(j).text());
					tyrover(j,ttr.length);
				}else	if(getkeycode(e)==38){
					j--;
					if(j==-1) j=ttr.length-1;
					tyr.val(ttr.eq(j).text());
					tyrover(j,ttr.length);
				}
				return;
			}
			$("#ttyr").css("left",tyr.offset().left).css("top",tyr.offset().top+tyr.outerHeight()-1).width(tyr.outerWidth());	//outerHeight()有margin是否选中的选项，注意！
			//$("#ttyr").css("left",(tyr.offset().left).toString()+"px").css("top",(tyr.offset().top+tyr.height()+5).toString()+"px").css("width",(tyr.width()+6).toString()+"px");	//原先的定位代码
			//		alert(tyr.offset().left);
			//e.preventDefault();
			if(tyr.val().length>0){	//输入框内容大于0就开始查询
				$.get("tyr.asp",{tyr:$(this).val()},function(data){
					if(!data.length){
						j=-1;
						$("#ttyr").css("visibility","hidden");
					}else{
						//alert(data[0].tyr);

						var ttyr="";
						for(var i=0;i<data.length;i++)	//for(var i=0;i<data.length&&i<=10;i++)最多显示10条，也可以通过数据库控制返回最多10条
						{
							ttyr+="<tr><td class='gac_c'>"+data[i].tyr+"</td></tr>";
							//alert(ttyr);
						}
						//alert(ttyr);
						$("#ttyr").html(ttyr).css("visibility","visible");
						$("#ttyr tr").mouseover(function(){	//对返回的dom进行mouseowver事件捕获
							$("#ttyr tr").eq(j).removeClass("gac_b");
							$(this).addClass("gac_b");	//添加css样式
							j=$("#ttyr tr").index($(this));
						}).mouseout(function(){	//对dom进行mouseout事件捕获
							$(this).removeClass("gac_b");	//移除css样式
						}).click(function(){
							tyr.val($(this).text());
							j=-1;
							$("#ttyr").css("visibility","hidden");
						});
						tyr.blur(function(){
							j=-1;
							setTimeout("$('#ttyr').css('visibility','hidden');", 200);	//设置延时隐藏列表的时间，以便有时间让click事件能取得数据
						});
					}
				},"json");
			}else{
				j=-1;
				$("#ttyr").css("visibility","hidden");	//输入框没有内容时隐藏提示框
			}
		}).keydown(function(e){
			if(getkeycode(e)==13) return false;
		});
		
		$(".opensidebar").click(function(){
			$("#content").css("margin","0 0 0 210px");
			$("#sidebar").show();
		});
		$(".closesidebar").click(function(){
			$("#content").css("margin","0");
			$("#sidebar").hide();
		});
		
		function customer_option(q){
			var query_sql_string="customer_id,customer_name,customer_address,customer_phone,customer_owner,salesman_name,equip_address,customer_memo,salesman_phone";
			$.getJSON("readCustomer.asp?l="+q+"&query="+query_sql_string,function(customerdata){
					//if(customerdata.length<20){
					//	$("#sidecontent").attr("size",customerdata.length).css("width","200px");
					//}
					//else{
					//	$("#sidecontent").attr("size","20").css("width","200px");
					//}
					$("#sidecontent").html("");
					$.each(customerdata,function(i,item){
						//$("#sidecontent").append("<option id='customer_"+item.customer_id+"' rel='"+						item.customer_name+"|"+						item.customer_owner+"|"+						item.customer_address+"|"+						item.customer_phone+"|"+						item.equip_address+"|"+						item.salesman_name+"|"+						item.customer_memo+"|"+						item.salesman_phone+						"' value='"+item.customer_id+"'>"+item.customer_name+"</option>");
						$("#sidecontent").append("<option id='customer_"+item.customer_id+"' value='"+item.customer_id+"'>"+item.customer_name+"</option>");
					});
					//$("#sidecontent").html(cdata);
					$("#sidecontent>option").dblclick(function(e){
						//alert($(this).attr("rel"));
						//var customer_array=$(this).attr("rel").split("|");
						//$("#client").val(customer_array[0]);
						//$("#contacts").val(customer_array[1]+" "+customer_array[2]+" "+customer_array[3]);
						//$("#hz").val(customer_array[5]);
						//$("#attentions").val(customer_array[6]);
						//$("#customer_id").val($(this).val());
				
						//alert(customerdata[$(this).index()].customer_name);
						var j=$(this).index();
						$("#client").val(customerdata[j].customer_name);
						$("#contacts").val(customerdata[j].customer_address+" "+customerdata[j].customer_owner+" "+customerdata[j].customer_phone);
						$("#hz").val(customerdata[j].salesman_name);
						$("#attentions").val(customerdata[j].customer_memo);
						$("#customer_id").val($(this).val());
						codeAddress(customerdata[j].customer_address,customerdata[j].customer_name);

						$("#dd>option").each(function(){
								//alert($(this).val());
							//if($(this).val()==customer_array[4]){
							if($(this).val()==customerdata[j].equip_address){
								$(this).attr("selected","selected");
								$("#didian").val(customerdata[j].equip_address);
								didian_xiangxing($("#didian").val(),$("#xx").val());
								return false;				//中断循环
							}
						});
					});
			});
		
		
		}
		
		$("#selCustomer").click(function(){
			$("#dd").attr("disabled","disabled");
			customer_option($("#quick").val());
		});
		$("#quick").keyup(function(){
			customer_option($(this).val());
		});
		$("#selDidian").click(function(){
			$("#content").css("margin","0");
			$("#sidebar").hide();
			$("#client").val("");
			$("#contacts").val("");
			$("#hz").val("");
			$("#attentions").val("");
			$("#customer_id").val(0);
			$("#dd").removeAttr("disabled");
	
			});
		
		
		$("#hdNumber").change(function(){
			if($(this).val()>1){
				if(!confirm("确定添加"+$(this).val()+"个相同的货柜？")){
					$(this).val(1);
				}
			}
		});
		$("#client,#contacts,#hz").click(function(){
			alert("请使用客户选择功能，直接录入功能已经关闭！");
		});
		
		var map;
		var myLatlng;
		var	geocoder;
		var marker;
		var infowindow;
		geocoder = new google.maps.Geocoder();
		marker=new google.maps.Marker();
		infowindow = new google.maps.InfoWindow();
		//地图初始化
		myLatlng = new google.maps.LatLng(29.868336, 121.54399);
		var mapOptions = {
			zoom: 6,                //缩放级别
			center: myLatlng,       //将地图的中心设置为指定的地理点 可以使用 0（最低缩放级别，在地图上可以看到整个世界）到 19（最高缩放级别，可以看到独立建筑物）之间的缩放级别
			mapTypeId: google.maps.MapTypeId.ROADMAP,   //ROADMAP-默认视图 SATELLITE-显示Google地球卫星图像 HYBRID-混合显示普通视图和卫星视图 TERRAIN-地形图
			mapTypeControl: true,
			mapTypeControlOptions: {
				style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
			},
			navigationControl: true,
			navigationControlOptions: {
				style: google.maps.NavigationControlStyle.SMALL,
				position: google.maps.ControlPosition.LEFT
			},
			scaleControl: true,    //比例尺
			scaleControlOptions: {
				position: google.maps.ControlPosition.BOTTOM_LEFT
			}
		};
		map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);//编写 JavaScript 函数创建“map”对象
		function codeAddress(addr,name) {
			var address = addr;
			if (geocoder) {
			 geocoder.geocode( { 'address': address}, function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {	
					map.setZoom(13);
					
						map.setCenter(results[0].geometry.location);
						marker.setOptions({
								map: map,
								position: results[0].geometry.location,
								title:name
						});
						var contentString = '<div id="content">'+
							'<h1 id="firstHeading">'+name+'</h1>'+
							'<div id="bodyContent">'+
							'<p>地址：' +address+'</p>'+
							'</div>'+
							'</div>';

						infowindow.setOptions({
								content: contentString
						});
						
						infowindow.open(map,marker);

						google.maps.event.addListener(marker, 'click', function() {
							infowindow.open(map,marker);
						});
					} else {
						alert("地图上未找到当前地址: " + status);
					}
				});
			}
		}
		
		$("#tyr").change(function(){
			
			$("#yb_freight").val($("#tyr option:selected").attr("name"));
		});
		
	});
</script>

<!--#include file="lib/keydown.asp"-->

</head>
<%
call CheckRights(1,3)
%>
<body>
<%
if request.form("tj")="下单" or request.form("tj")="保存" Then
	if request.form("tj")="下单" Then post=2
	if request.form("tj")="保存" Then post=1
	client=trim(SafeRequest("client",0))
	contacts=trim(SafeRequest("contacts",0))
	hz=trim(SafeRequest("hz",0))
	attentions=trim(SafeRequest("attentions",0))
	xdr=trim(SafeRequest("xdr",0))
	if xdr="" then error_write "3","没有填写[下单人]"
	sj=trim(SafeRequest("sj",0))
	rq=trim(SafeRequest("rq",0))
	if rq="" then error_write "1","没有填写[日期]"
	xdrq=trim(SafeRequest("xdrq",0))
	if xdrq="" then error_write "4","没有填写[下单日期]"
	tyr=trim(SafeRequest("tyr",0))
	if tyr="" then error_write "2","没有填写[托运人]"
	yb_freight=SafeRequest("yb_freight",1)
	'dd=trim(SafeRequest("dd",0))
	dd=trim(SafeRequest("didian",0))
	if dd="" then error_write "5","没有填写[地点]"
	cmhc=trim(SafeRequest("cmhc",0))
	tdh=trim(SafeRequest("tdh",0))
	xx=trim(SafeRequest("xx",0))
	lrsj=trim(SafeRequest("lrsj",0))
	if lrsj="" then error_write "23","没有填写[录入日期]"
	tx=trim(SafeRequest("tixiang",0))
	hx=trim(SafeRequest("huanxiang",0))
	yj=trim(SafeRequest("yj",0))
	if yj="" then yj=0
	jsj=trim(SafeRequest("jsj",0))
	if jsj="" then jsj=0
	chanzhi=trim(SafeRequest("chanzhi",0))
	if chanzhi="" then chanzhi=0
	jgf=trim(SafeRequest("jgf",0))
	if jgf="" then jgf=0
	yfjgf=trim(SafeRequest("yfjgf",0))
	if yfjgf="" then yfjgf=0
	dz=trim(SafeRequest("dz",0))
	if dz="" then dz=0
	hdNumber=SafeRequest("hdNumber",1)
	if saferequest("customer_id",0)="" then
		customer_id=0
	else
		customer_id=SafeRequest("customer_id",1)
	end if
	sql="insert into yb(sj,rq,tyr,yb_freight,dd,cmhc,tdh,xx,lrsj,client,contacts,hz,attentions,gxry,post,xdrq,xdr,xdrid,tx,hx,yj,jsj,jgf,yfjgf,dz,yb_customer,chanzhi) values('"&sj&"','"&rq&"','"&tyr&"',"&yb_freight&",'"&dd&"','"&cmhc&"','"&tdh&"','"&xx&"','"&lrsj&"','"&client&"','"&contacts&"','"&hz&"','"&attentions&"','"&session("MM_Name")&"',"&post&",'"&xdrq&"','"&xdr&"',"&session("MM_ID")&",'"&tx&"','"&hx&"',"&yj&","&jsj&","&jgf&","&yfjgf&","&dz&","&customer_id&","&chanzhi&")"
	'response.write sql
	'response.end
	set cmd=Server.CreateObject("ADODB.Command")
	cmd.ActiveConnection=conn
	cmd.CommandText = sql
	for i=1 to hdNumber 
		cmd.Execute
	next
	if hdNumber>1 then
		response.write(hdNumber&"张货单下单成功，察看添加的数据请查询！")
		response.end
	else
		set rs_new=server.createobject("adodb.recordset")
		sql_new="select id from yb where id=(select max(id) as Last_Id from yb)"
		rs_new.open sql_new,conn,1,1
		id=rs_new("id")
		rs_new.close
		view_url="view_cw.asp?id="&id
		response.Redirect(view_url)
	end if
end if

%>
<div id="sidebar">
	<button class="closesidebar" type="button" style="width:200px">关闭</button>
	<input id="quick" style="width:198px" />
	<div>
		<select id="sidecontent" size="20" style="width:200px"></select>
	</div>
</div>
<div id="content">
<form name="form1" method="post" action="#">
<table class="contable">
	<thead>
		<tr>
			<th colspan="4" class="lh"><font size="4">基本信息</font>(录入时间:<input class="datepicker" name="lrsj" id="lrsj" size="10" value="<%=date()%>" />&nbsp;下单人:<input name="xdr" id="xdr" size="10" readonly="readonly" value="<%=session("MM_Name")%>" />)
			</th>
		</tr>
	</thead>
  <tr>
    <th>客户名称</th>
    <td colspan="3">
			<input name="client" id="client" size="80" readonly="readonly" />
			<input name="customer_id" id="customer_id" type="hidden" value="0" />
			<button id="selCustomer" class="opensidebar" type="button">选择客户</button>
		</td>
	</tr>
	<tr>
    <th>联系方式</th>
    <td colspan="3"><input name="contacts" id="contacts" size="80" readonly="readonly" /></td>
	</tr>
	<tr>
    <th>业务员</th>
    <td colspan="3"><input name="hz" id="hz" size="80" readonly="readonly" /></td>
	</tr>
  <tr>
    <th>托运人</th>
    <td><select id="tyr" name="tyr">
			<option disabled="disabled" selected="selected">托运人</option>
		<%
		set rs_tyr = Server.CreateObject("ADODB.Recordset")
sql="select freight_id,freight_name from freight order by freight_name"
rs_tyr.open sql,conn,1,1
While Not rs_tyr.eof
%>
	 <option name="<%=rs_tyr("freight_id")%>" value="<%=rs_tyr("freight_name")%>"><%=rs_tyr("freight_name")%></option>
<%
rs_tyr.movenext
Wend
rs_tyr.close
%>					
		</select>
		<input type="hidden" id="yb_freight" name="yb_freight" />
</td>
    <th>货单日期</th>
    <td><input class="datepicker" name="rq" id="rq" value="<%=DateAdd("d",1,date())%>" /></td>
  </tr>
  <tr>
    <th>地点</th>
    <td><input name="didian" id="didian" type="hidden" />
	  <select name="dd" id="dd" disabled="disabled">
        <option value=""></option>
		<%
		set rs_dd = Server.CreateObject("ADODB.Recordset")
		sql="select didian from yj group by didian"
		rs_dd.open sql,conn,1,1
		while not rs_dd.eof
		%>
        <option value="<%=rs_dd("didian")%>"><%=rs_dd("didian")%></option>
	<%
			rs_dd.movenext()
		wend
		rs_dd.close
	%>
      </select><button id="selDidian" type="button">选择地点</button>
		</td>
		<th>时间</th>
		<td>
		<select id="sj" name="sj">
			<option value="0:00">0:00</option>
			<option value="1:00">1:00</option>
			<option value="2:00">2:00</option>
			<option value="3:00">3:00</option>
			<option value="4:00">4:00</option>
			<option value="5:00">5:00</option>
			<option value="6:00">6:00</option>
			<option value="7:00">7:00</option>
			<option value="8:00">8:00</option>
			<option value="9:00">9:00</option>
			<option value="10:00">10:00</option>
			<option value="11:00">11:00</option>
			<option value="12:00">12:00</option>
			<option value="13:00">13:00</option>
			<option value="14:00">14:00</option>
			<option value="15:00">15:00</option>
			<option value="16:00">16:00</option>
			<option value="17:00">17:00</option>
			<option value="18:00">18:00</option>
			<option value="19:00">19:00</option>
			<option value="20:00">20:00</option>
			<option value="21:00">21:00</option>
			<option value="22:00">22:00</option>
			<option value="23:00">23:00</option>
		</select>
	</td>
	</tr>
	<tr>
    <th>船名/航次</th>
    <td><input name="cmhc" id="cmhc" /><button id="selShip" class="opensidebar" type="button">选择船舶</button></td>
		<th>下单日期</th>
		<td><input class="datepicker" name="xdrq" id="xdrq" value="<%=date()%>">
		</td>
  </tr>
  <tr>
    <th>提单号</th>
    <td><input name="tdh" id="tdh" /></td>
    <th>箱型</th>
    <td>
		<select name="xx" id="xx">
        <option value="40">40</option>
        <option value="20">20</option>
        <option value="45">45</option>
		</select>
	  </td>
  </tr>
  <tr>
    <th>提箱</th>
    <td>
		<select name="tixiang" id="tixiang">
        <option value=""></option>
		<%
		set rs_tx = Server.CreateObject("ADODB.Recordset")
		sql="select * from tx"
		rs_tx.open sql,conn,1,1
		while not rs_tx.eof
		%>
        <option value="<%=rs_tx("tixiang")%>" ><%response.write(rs_tx("tixiang")&"("&rs_tx("tixiangjiage")&")")%></option>
	<%
			rs_tx.movenext()
		wend
		rs_tx.close
	%>
      </select>
</td>
    <th>还箱</th>
    <td>
	<select name="huanxiang" id="huanxiang">
        <option value=""></option>
		<%
		set rs_hx = Server.CreateObject("ADODB.Recordset")
		sql="select * from hx"
		rs_hx.open sql,conn,1,1
		while not rs_hx.eof
		%>
        <option value="<%=rs_hx("huanxiang")%>" ><%response.write(rs_hx("huanxiang")&"("&rs_hx("huanxiangjiage")&")")%></option>
	<%
			rs_hx.movenext()
		wend
		rs_hx.close
	%>
      </select>
</td>
  </tr>
  <tr>
    <th>注意事项</th>
    <td colspan="3"><textarea rows="3" cols="80" id="attentions" name="attentions"></textarea></td>
	</tr>
  <tr>
    <th colspan="4">货柜数量:<input id="hdNumber" name="hdNumber" type="text" size="2" maxLength="2" value="1" />&nbsp;&nbsp;&nbsp;&nbsp;
			<input class="bt" type="submit" name="tj" value="保存" />&nbsp;&nbsp;&nbsp;&nbsp;
			<input class="bt" type="submit" name="tj" value="下单" onClick="return confirm('确定下单吗？');" />&nbsp;&nbsp;&nbsp;&nbsp;
			<input class="bt" type="reset" />
		</th>
	</tr>
</table>
<div style="display:none">
应收运价：<input name="yj" id="yj" readonly="readonly" value="0" /> 运价:<span id="zdyj"></span> 运价=地点&amp;箱型
<br />
应付运价：<input name="jsj" id="jsj" readonly="readonly" value="0" />
<br />
应收进港费：<input name="jgf" id="jgf" readonly="readonly" value="0" /> 应收进港费=提箱+还箱
<br />
应付进港费：<input name="yfjgf" id="yfjgf" readonly="readonly" value="0" /> 
<br />
垫资：<input name="dz" id="dz" readonly="readonly" title="垫资=（应付运费+进港费）×60%" value="0" /> 
<br />
产值：<input name="chanzhi" id="chanzhi" readonly="readonly" value="0" /> 
</div>
</form>
<div id="map_canvas" style="width: 100%; height: 500px"></div>
</div>
</body>
<%
conn.close
Set conn=nothing
%>
</html>
